#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0)
#define endl '\n'
#define int long long
#define ar array<int, 2>
#define arr array<int, 3>
const int N = 2e5 + 5, M = 2 * N;
const int inf = 0x3f3f3f3f3f3f3f3f;
int mod = 998244353; //1e9+7;
int t, n, m, k;
ar st[N];
signed main()
{
ios;
#ifdef DEBUG
freopen("../1.in", "r", stdin);
#endif
// 这题还是可以刷的。
// 就是实现技巧如果好的话。。会很舒服。。
// 虽然我自己做出来的哈哈哈。。
cin >> n >> m;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; ++i)
cin >> a[i], b[i] = a[i];
int l = 0;
while (m--)
{
int x, y;
cin >> x >> y;
while (l && st[l][1] <= y)
l--;
st[++l] = {x, y};
}
sort(a + 1, a + st[1][1] + 1);
int x = 1, y = st[1][1];
st[l + 1][1] = 0; //这个很细节。l在进退的时候 这个位置是有可能被污染过的。
// 后面我们要用到。。所以要给他稳定的重置为0
for (int i = 1; i <= l; ++i)
{
auto &[u, v] = st[i];
for (int j = v; j > st[i + 1][1]; j--)
if (u == 1)
b[j] = a[y--];
else
b[j] = a[x++];
}
for (int i = 1; i <= n; ++i)
cout << b[i] << " ";
};
268C - Beautiful Sets of Points | 1391C - Cyclic Permutations |
11A - Increasing Sequence | 1406A - Subset Mex |
1365F - Swaps Again | 50B - Choosing Symbol Pairs |
1719A - Chip Game | 454B - Little Pony and Sort by Shift |
1152A - Neko Finds Grapes | 1719B - Mathematical Circus |
1719C - Fighting Tournament | 1642A - Hard Way |
285C - Building Permutation | 1719E - Fibonacci Strings |
1696C - Fishingprince Plays With Array | 1085A - Right-Left Cipher |
1508B - Almost Sorted | 1690C - Restoring the Duration of Tasks |
1055A - Metro | 1036D - Vasya and Arrays |
1139C - Edgy Trees | 37A - Towers |
353A - Domino | 409H - A + B Strikes Back |
1262A - Math Problem | 158C - Cd and pwd commands |
194A - Exams | 1673B - A Perfectly Balanced String |
1104B - Game with string | 1169B - Pairs |